using System;
using System.IO;


namespace CommonTypes
{
    // all the application path managment must take place here and not in different paces into the code
    //Extensions Managment sould be paced here .

    /// <summary>
    /// Manages the Paths and Directories of the Application . Implemented as singleton.
    /// </summary>
	public class DirectoriesManager
	{

        public  string m_WorkingFilePath;
        public string m_WorkingFileName;

        private static  DirectoriesManager instance;
        public static DirectoriesManager Instance
        {
            get
            {
                if (instance == null)
                    instance = new DirectoriesManager();
                return instance;
            }
        }

        private DirectoriesManager()
        {
           // projectPath = "C:" + @"\Test";
          //  workingFileName = "TestProject";
        }

		private  string sectionsDatabasePath = "";
		private  string AnasisDir = "";

        public  void InitializeDirectories(string initDir)
		{
			sectionsDatabasePath = initDir + @"\DataBase\SteelDataSet.xml";
			AnasisDir = initDir +  @"\Anasis";		
		}

		public  string CreateProjectDirectory(string ProjectName,string ProjectPath)
		{

			int index  = ProjectName.IndexOf('.');

			if (index > 0) 
				ProjectName = ProjectName.Substring(0,index); 

			Directory.CreateDirectory(ProjectPath + ProjectName); 
			
			string mainDir = ProjectPath + ProjectName + @"\";

            m_WorkingFilePath = mainDir;
			return mainDir;
		}

        string T3Ldirectory;

		public string CreateT3LDirectory()
		{

            Directory.CreateDirectory(m_WorkingFilePath + @"\T3L");

            string createdDir = m_WorkingFilePath + @"\T3L";
            T3Ldirectory = createdDir;
			return createdDir;            
		}

        public string t3lFileName;
        public string t3lFullPath;

        public void SetUpt3LFullPath(string path)
        {
            t3lFileName = m_WorkingFileName;

            int index = m_WorkingFileName.IndexOf('.');

            if (index > 0)
                t3lFileName = m_WorkingFileName.Substring(0, index);

            t3lFullPath = String.Format(path + @"\{0}.t3l", t3lFileName);
        }

		public string GetAnasisPath()
		{
            return AnasisDir;		
		}
        public string t3lpath
        {
            get
            {
                string t3lPath = m_WorkingFilePath + "T3L";
                return t3lPath;
            }
        }

        public string GetResultsPath()
        {
            int index = m_WorkingFileName.IndexOf('.');
            string jobFileName = m_WorkingFileName.Substring(0, index);

            string t3lFileName = jobFileName;
            string t3lPath = m_WorkingFilePath + "T3L";

            string path = t3lPath + "\\" + jobFileName + ".ajf\\" + jobFileName + ".res";
            return path;
        }
		
	}
}
